package com.another.bidservice.service.impl;

import com.another.bidservice.entity.TStatic;
import com.another.bidservice.dao.jpa.StaticJPADao;
import com.another.bidservice.dao.mapper.StaticDao;
import com.another.bidservice.service.IStaticService;
import com.another.common.utils.Page;
import com.another.common.utils.common.EmptyUtil;
import com.another.common.utils.common.MyException;
import com.another.common.utils.result.Result;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigInteger;
import java.util.List;
@Service
@Transactional
public class StaticServiceImpl extends BaseServiceImpl implements IStaticService {

    private Logger logger=Logger.getLogger(this.getClass());
    
    @Autowired
    private StaticDao staticDao;
    
    @Autowired
    private StaticJPADao staticJPADao;
    
    @Override
    public Result getList(TStatic tStatic) {
        String sql="select * from db_sys.vt_static";
        List<TStatic> list=staticDao.getList(sql);
        if (EmptyUtil.isEmpty(list)) {
            return Result.success("没有查询到数据！", "");
        } else {
            return Result.success(list);
        }
    }

    
    @Override
    public Result insertList(List<TStatic> tStatics) {
        int ret = staticDao.insertList(tStatics);
        if(ret==tStatics.size()){
            return Result.success("添加成功！","");
        }else{
            throw new MyException(101, "添加失败！");
        }
    }

    
    @Override
    public Result deleteList(List<Integer> rowid) {
        int ret = staticDao.deleteList(rowid);
        if(ret==rowid.size()){
            return Result.success("删除成功！","");
        }else{
            throw new MyException(101, "删除失败！");
        }
    }
    
    @Override
    public Result updateList(List<TStatic> tStatics) {
        try {
            int ret = staticDao.updateList(tStatics);
            return Result.success("修改成功！","");
        }catch (Exception e){
            logger.info(e.getMessage(),e);
            throw new MyException(101, "修改失败！");
        }
    }
    
    
    @Override
    public Result insertStatic(TStatic tStatic) {
        try {
            int ret = staticDao.insertStatic(tStatic);
            return Result.success("添加成功！", "");
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            throw new MyException(101, "添加失败！");
        }
    }

    @Override
    public Result updateStatic(TStatic tStatic) {
        try {
            int ret = staticDao.updateStatic(tStatic);
            return Result.success("修改成功！", "");
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            throw new MyException(101, "修改失败！");
        }
    }

    @Override
    public Result deleteStatic(TStatic tStatic) {
        try {
            int ret = staticDao.deleteStatic(tStatic);
            return Result.success("删除成功！", "");
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            throw new MyException(101, "删除失败！");
        }
    }

    /**
     * @author Another
     * @description :  获取状态
     * @date 2020/3/17 9:54:20
     * @param tStatic
     * @return com.another.exhibitioncommon.utils.result.Result
     * @version : 1.0
     */
    @Override
    public Result publicStatus(TStatic tStatic) {

        if (EmptyUtil.isEmpty(tStatic.getValueSetCode())) {
            return Result.error("参数没传!");
        }

        List<TStatic> list=staticJPADao.findAllByValueSetCode(tStatic.getValueSetCode());

        return Result.success(list);

    }
}



